package com.gshrms.common.core.domain;

import java.util.HashMap;
import java.util.Objects;

import com.gshrms.common.constant.HttpStatus;
import com.gshrms.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * 操作消息提醒
 *
 * @author ruoyi
 */
@ApiModel(description = "响应消息返回类")
public class AjaxResult<T> {


    /**
     * HTTP状态码
     */
    @ApiModelProperty(value = "状态码")
    private Integer code;

    /**
     * 返回信息
     */
    @ApiModelProperty(value = "描述")
    private String msg;

    /**
     * 返回的数据
     */
    @ApiModelProperty(value = "数据")
    private T data;

    public AjaxResult() {
    }

    public AjaxResult(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public AjaxResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static AjaxResult getErrorResult(int code, String msg) {
        AjaxResult resultEntity = new AjaxResult();
        resultEntity.setCode(code);
        resultEntity.setMsg(msg);
        return resultEntity;
    }

    public static AjaxResult getErrorResult(String msg) {
        AjaxResult resultEntity = new AjaxResult();
        resultEntity.setCode(HttpStatus.ERROR);
        resultEntity.setMsg(msg);
        return resultEntity;
    }

    public static AjaxResult getErrorResult() {
        AjaxResult resultEntity = new AjaxResult();
        resultEntity.setCode(HttpStatus.ERROR);
        resultEntity.setMsg(org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
        return resultEntity;
    }

    public static <T> AjaxResult<T> getOkResult(final T data) {
        AjaxResult<T> tResultEntity = new AjaxResult<>();
        tResultEntity.setCode(org.springframework.http.HttpStatus.OK.value());
        tResultEntity.setMsg(org.springframework.http.HttpStatus.OK.getReasonPhrase());
        tResultEntity.setData(data);
        return tResultEntity;
    }

    public static <T> AjaxResult<T> getOkResult() {
        AjaxResult<T> tResultEntity = new AjaxResult<>();
        tResultEntity.setCode(org.springframework.http.HttpStatus.OK.value());
        tResultEntity.setMsg(org.springframework.http.HttpStatus.OK.getReasonPhrase());
        return tResultEntity;
    }

    public static <T> AjaxResult<T> getOkResult(String msg) {
        AjaxResult<T> tResultEntity = new AjaxResult<>();
        tResultEntity.setCode(org.springframework.http.HttpStatus.OK.value());
        tResultEntity.setMsg(msg);
        return tResultEntity;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }


    /**
     * 返回成功消息
     *
     * @return 成功消息
     */
    public static <T> AjaxResult<T> success() {
        return AjaxResult.success("操作成功");
    }

    /**
     * 返回成功数据
     *
     * @return 成功消息
     */
    public static <T> AjaxResult<T> success(Object data) {
        return AjaxResult.success("操作成功", data);
    }

    /**
     * 返回成功消息
     *
     * @param msg 返回内容
     * @return 成功消息
     */
    public static <T> AjaxResult<T> success(String msg) {
        return AjaxResult.success(msg, null);
    }

    /**
     * 返回成功消息
     *
     * @param msg  返回内容
     * @param data 数据对象
     * @return 成功消息
     */
    public static <T> AjaxResult<T> success(String msg, Object data) {
        return new AjaxResult(HttpStatus.SUCCESS, msg, data);
    }

    /**
     * 返回警告消息
     *
     * @param msg 返回内容
     * @return 警告消息
     */
    public static <T> AjaxResult<T> warn(String msg) {
        return AjaxResult.warn(msg, null);
    }

    /**
     * 返回警告消息
     *
     * @param msg  返回内容
     * @param data 数据对象
     * @return 警告消息
     */
    public static <T> AjaxResult<T> warn(String msg, Object data) {
        return new AjaxResult(HttpStatus.WARN, msg, data);
    }

    /**
     * 返回错误消息
     *
     * @return 错误消息
     */
    public static <T> AjaxResult<T> error() {
        return AjaxResult.error("操作失败");
    }

    /**
     * 返回错误消息
     *
     * @param msg 返回内容
     * @return 错误消息
     */
    public static <T> AjaxResult<T> error(String msg) {
        return AjaxResult.error(msg, null);
    }

    /**
     * 返回错误消息
     *
     * @param msg  返回内容
     * @param data 数据对象
     * @return 错误消息
     */
    public static <T> AjaxResult<T> error(String msg, Object data) {
        return new AjaxResult(HttpStatus.ERROR, msg, data);
    }

    /**
     * 返回错误消息
     *
     * @param code 状态码
     * @param msg  返回内容
     * @return 错误消息
     */
    public static <T> AjaxResult<T> error(int code, String msg) {
        return new AjaxResult(code, msg, null);
    }

}
